<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!-- 一些信息 -->
      <el-col :xs="24" :sm="10">
        <el-card class="info-card">
          <div slot="header">信息</div>
          <v-l-info :user="user" :avatar="avatar" ref="userInfo"/>
        </el-card>
      </el-col>
      <!-- 一些设置 -->
      <el-col :xs="24" :sm="14">
        <el-card class="sitting-card">
          <div slot="header">设置</div>
          <el-tabs type="border-card">
            <!-- 基本资料 -->
            <el-tab-pane>
              <span slot="label"><i class="tabs-icon el-icon-postcard" />基本资料</span>
              <v-r-profile :user="user"/>
            </el-tab-pane>
            <!-- 登录密码 -->
            <el-tab-pane>
              <span slot="label"><i class="tabs-icon el-icon-lock" />登录密码</span>
              <v-r-password :user="user"/>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>

import axios from "axios";

export default {
  name: 'Profile',
  components: {
    'v-r-profile': () => import('../../view/profile/r-profile'),
    'v-r-password': () => import('../../view/profile/r-password'),
    'v-l-info': () => import('../../view/profile/l-info')
  },
  data() {
    return {
      user:{},
      avatar:''
    }
  },

  methods: {
    getUserInfo() {
      let jwtToken = localStorage.getItem('jwtToken');
      axios.get('/api/users/info', {params: {}, headers: {jwtToken: jwtToken}})
        .then(result => {
          if (result.data.code === 200) {
            this.user = result.data.data;
            this.avatar = '../'+this.user.avatar
          }
        }).catch(e => {
        this.$message({
          showClose: true,
          message: '服务器去火星了！',
          type: 'error',
          duration: 2000
        });
      })
    }
  },
  created() {
      this.getUserInfo();
  }
}
</script>

<style lang="scss">

.el-card {
  &__header, &__body {
    padding: 12px;
  }
}

.sitting-card {
  .el-card__body {
    padding: 0;
  }

  .el-tabs {
    border-top: none;
    border-left: none;
    border-right: none;
  }

  .tabs-icon {
    margin-right: 5px;
  }
}
</style>

<style scoped lang="scss">

</style>
